# encoding:utf8
"""
@File        : suning.py
@Time        : 2019/7/15 15:15
@Author      : zhaoy
@Email       : zhaoyao@shandiangou.cc
@Description :
"""
import matplotlib.pyplot as plt
import pandas as pd
import pymongo


class Analysis(object):

    def __init__(self):
        url = 'mongodb://192.168.50.181:27017/ods'
        client = pymongo.MongoClient(host='192.168.50.181', port=27017)
        self.db = client.ods
        self.read_data()

    def read_data(self):
        stores = self.db.get_collection('suning_store').find({})
        goods = self.db.get_collection('suning_goods').find({})
        goods_price = self.db.get_collection('suning_goods_price').find({})
        self.stores = pd.DataFrame(list(stores))
        self.goods = pd.DataFrame(list(goods))
        self.goods_price = pd.DataFrame(list(goods_price))

    def expore_data(self):
        row, col = self.goods.shape
        print('rows: %s, cols: %s' % (row, col))

        # 分析销量 异常值
        self.goods['goodsSaleCount'].replace(to_replace='', value=None, inplace=True)
        self.goods['goodsSaleCount'] = self.goods['goodsSaleCount'].astype(int)
        desc = self.goods['goodsSaleCount'].describe()
        print(desc)

        # 可视化 异常值
        plt.rcParams['font.sans-serif'] = ['SimHei']
        plt.rcParams['axes.unicode_minus'] = False

        plt.figure()
        # 展示箱线图
        self.goods.boxplot(['goodsSaleCount'])
        plt.show()

        # 展示柱状图
        self.goods.hist(['goodsSaleCount'])
        plt.show()

    def calc(self):
        pass

    def dianpujunxiao(self):
        """
        店铺每个商品的销量
        :return:
        """
        self.goods['poiName']
        pass

    def dianpuxiaoliangzuidadeshangpin(self):
        """
        店铺销量最好的商品
        :return: 返回前10
        """
        pass

    def dianpuzongxiaoliao(self):
        """
        店铺总销量分布
        :return:
        """
        pass

    def dianpuluodian(self):
        """
        店铺地图落点分布
        :return:
        """
        pass


if __name__ == '__main__':
    Analysis().expore_data()
